package com.rainbow.service.impl;

import com.rainbow.dao.ProductDao;
import com.rainbow.service.ProductService;
import com.rainbow.domain.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductDao productDao;

    @Override
    public Product findByPid(Integer pid) {
        return productDao.findById(pid).get();
    }

    // - 库存, 不能开启
    @Override
//    @Transactional(rollbackFor = Exception.class)
    public void minusStock(Integer pid,Integer number) {
        throw new RuntimeException("库存不足!");
//        Product product = productDao.findById(pid).get();
//        if(product.getStock()<number){
//            throw new RuntimeException("库存不足!");
//        }
//        // 省略校验
//        product.setStock(product.getStock()-number);
////        try{
////            int i = 1/0;
////        }catch (Exception e){
////            throw new RuntimeException("error---");
////        }
//
//        productDao.save(product);
    }
}
